<?php
namespace Modules\ShopAdmin\Http\Controllers;
use Illuminate\Http\Request;
use Modules\Admin\Http\Requests\CommonStatusRequest;
use Modules\Admin\Http\Requests\CommonSortRequest;
use Modules\Admin\Http\Requests\CommonDeleteRequest;
use Modules\Admin\Http\Requests\CommonDeleteAllRequest;
use Modules\ShopAdmin\Models\ShopTopSearche as ShopTopSearcheModel;
class TopSearchController extends CommonShopController
{
	/**
	 * @name  列表
	 */
    public function index()
    {  
		$status = ShopTopSearcheModel::common_status();
        return view('shopadmin::top_search.index',compact('status'));
    }
	/**
	 * @name  列表数据
	 */
	 
    public function data(Request $request)
    {
	    $model = ShopTopSearcheModel::query();
		$params = $request->all();
		$model = query_condition($model,$params,'name');
		if(isset($params['searches_status']) && $params['searches_status'] != ''){
			$model = $model->where('searches_status',$params['searches_status']);
		}	
        $res = $model->orderBy('sort','asc')
				->orderBy('id','desc')  
				->paginate($params['limit'])
				->toArray();
        return response()->json(['code' => 0, 'msg'   => config('admin.limit_msg'),'count' => $res['total'],'data'  => $res['data'],'rel'=>1]);
    }
	/**
	 * @name  添加页面
	 */
    public function create()
    { 
		return view('shopadmin::top_search.create');
    }
	/**
	 * @name  添加数据处理 
	 */
    public function store(Request $request)
    {
		return (new ShopTopSearcheModel())->common_create($request->all(),route('shop_admin.top_search.index'));  
    }
	/**
	 * @name  编辑页面
	 */
    public function edit($id)
    {
	
		$info = ShopTopSearcheModel::find($id)->toArray();
		return view('shopadmin::top_search.edit',compact('info','product_type_info'));
    }
	/**
	 * @name  编辑数据处理
	 */
    public function update(Request $request,$id)
    {
		return (new ShopTopSearcheModel())->common_update($request->all(),$id,route('shop_admin.top_search.index')); 
    }
	/**
	 * @name 状态数据处理
	 */
    public function status(CommonStatusRequest $request,$id)
    {
		return (new ShopTopSearcheModel())->common_status_update($request->all(),$id,route('shop_admin.top_search.index')); 
    }
	
	/**
	 * @name 首页展示
	 */
    public function searches_status(Request $request,$id)
    {
		return (new ShopTopSearcheModel())->common_status_update($request->all(),$id,route('shop_admin.top_search.index')); 
    }
	/**
	 * @name  排序数据处理
	 */
    public function sorts(CommonSortRequest $request,$id)
    {
		return (new ShopTopSearcheModel())->common_status_update($request->all(),$id,route('shop_admin.top_search.index'));  
    }
	/**
	 * @name  删除数据处理
	 */
    public function destroy(CommonDeleteRequest $request)
    {
		return (new ShopTopSearcheModel())->common_destroy($request->get('id'),route('shop_admin.top_search.index'));  
    }
	
}
